package com.wabbei.friendcenter.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.webbei.friendcenter.service.MyFriendCenter;

public class CommentFriendCustomsByAjAxAction extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	private Long customid;
	private String textContent;
	private Date currentDate;
	private MyFriendCenter friservice;
	
	private String sessionName;
	private int sourse;
	
	public String execute(){
		System.out.println(textContent);
		System.out.println("sourse:"+sourse);
		sessionName=(String)ServletActionContext.getContext().getSession().get("username");
		currentDate=new Date();
		if(sourse!=1){
			sourse=0;
		}
		int i=friservice.InsertNewComment(customid,sessionName,textContent,currentDate,sourse);
		System.out.println("i:"+i);
		ServletActionContext.getResponse().setContentType("text/html");
		try {
			if(i==1){
				ServletActionContext.getResponse().getWriter().write("success");
			}else{
				ServletActionContext.getResponse().getWriter().write("fail");
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	
	public String getSessionName() {
		return sessionName;
	}

	public void setSessionName(String sessionName) {
		this.sessionName = sessionName;
	}

	
	public Date getCurrentDate() {
		return currentDate;
	}

	public void setCurrentDate(Date currentDate) {
		this.currentDate = currentDate;
	}

	public MyFriendCenter getFriservice() {
		return friservice;
	}

	public void setFriservice(MyFriendCenter friservice) {
		this.friservice = friservice;
	}

	public Long getCustomid() {
		return customid;
	}

	public void setCustomid(Long customid) {
		this.customid = customid;
	}

	public String getTextContent() {
		return textContent;
	}

	public void setTextContent(String textContent) {
		this.textContent = textContent;
	}

	public int getSourse() {
		return sourse;
	}

	public void setSourse(int sourse) {
		this.sourse = sourse;
	}
}
